|
1
|
|
|
import React, { Component } from "react" |
|
2
|
|
|
import { mapPositionCode } from "../scripts/helper" |
|
3
|
|
|
|
|
4
|
|
|
import "./player.scss" |
|
5
|
|
|
import { Link } from "gatsby" |
|
6
|
|
|
|
|
7
|
|
|
// eslint-disable-next-line |
|
8
|
|
|
String.prototype.replaceAll = function(search, replacement) { |
|
9
|
|
|
var target = this |
|
10
|
|
|
return target.replace(new RegExp(search, "g"), replacement) |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
*/ |
|
15
|
|
|
class PlayerDetail extends Component { |
|
16
|
|
|
renderPlayerName = player => ( |
|
17
|
|
|
<h1 className={"player-detail__name"}> |
|
18
|
|
|
<span className={"player-detail__name-first"}> |
|
19
|
|
|
{player.field_firstname} |
|
20
|
|
|
</span> |
|
21
|
|
|
<span className={"player-detail__name-last"}> |
|
22
|
|
|
{player.field_lastname} |
|
23
|
|
|
</span> |
|
24
|
|
|
</h1> |
|
25
|
|
|
) |
|
26
|
|
|
renderPlayerImage = player => ( |
|
27
|
|
|
<div className={"bg-green-mask"}> |
|
28
|
|
|
<div |
|
29
|
|
|
className={"player-detail__bg-avatar"} |
|
30
|
|
|
style={ |
|
31
|
|
|
player.relationships.field_image && { |
|
32
|
|
|
backgroundImage: `url(${player.relationships.field_image.localFile.childImageSharp.fixed.src})`, |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
/> |
|
36
|
|
|
<div className={"bg-white-end"} /> |
|
37
|
|
|
</div> |
|
38
|
|
|
) |
|
39
|
|
|
renderPlayerHeader = player => ( |
|
40
|
|
|
<header className={"player-detail__header"}> |
|
41
|
|
|
{this.renderPlayerName(player)} |
|
42
|
|
|
{this.renderPlayerImage(player)} |
|
43
|
|
|
|
|
44
|
|
|
<div className={"player-detail__bg-shirt-number"} aria-hidden="true"> |
|
45
|
|
|
{player.field_shirtnumber || ""} |
|
46
|
|
|
</div> |
|
47
|
|
|
</header> |
|
48
|
|
|
) |
|
49
|
|
|
renderPlayerStats = player => ( |
|
50
|
|
|
<aside className={"player-detail__statistics"}> |
|
51
|
|
|
<section className={"player-detail__statistics-item"}> |
|
52
|
|
|
<div className={"player-detail__statistics-item__number"}> |
|
53
|
|
|
{player.field_stats_games || "0"} |
|
54
|
|
|
</div> |
|
55
|
|
|
<div className={"player-detail__statistics-item__label"}> |
|
56
|
|
|
Wedstrijden |
|
57
|
|
|
</div> |
|
58
|
|
|
</section> |
|
59
|
|
|
|
|
60
|
|
|
{player.field_position === "k" && ( |
|
61
|
|
|
<section className={"player-detail__statistics-item"}> |
|
62
|
|
|
<div className={"player-detail__statistics-item__number"}> |
|
63
|
|
|
{player.field_stats_cleansheets || "0"} |
|
64
|
|
|
</div> |
|
65
|
|
|
<div className={"player-detail__statistics-item__label"}> |
|
66
|
|
|
Cleansheets |
|
67
|
|
|
</div> |
|
68
|
|
|
</section> |
|
69
|
|
|
)} |
|
70
|
|
|
{player.field_position !== "k" && ( |
|
71
|
|
|
<section className={"player-detail__statistics-item"}> |
|
72
|
|
|
<div className={"player-detail__statistics-item__number"}> |
|
73
|
|
|
{player.field_stats_goals || "0"} |
|
74
|
|
|
</div> |
|
75
|
|
|
<div className={"player-detail__statistics-item__label"}> |
|
76
|
|
|
Doelpunten |
|
77
|
|
|
</div> |
|
78
|
|
|
</section> |
|
79
|
|
|
)} |
|
80
|
|
|
<section className={"player-detail__statistics-item"}> |
|
81
|
|
|
<div className={"player-detail__statistics-item__number"}> |
|
82
|
|
|
{player.field_stats_cards_yellow || "0"} |
|
83
|
|
|
</div> |
|
84
|
|
|
<div className={"player-detail__statistics-item__label"}> |
|
85
|
|
|
Gele kaarten |
|
86
|
|
|
</div> |
|
87
|
|
|
</section> |
|
88
|
|
|
<section className={"player-detail__statistics-item"}> |
|
89
|
|
|
<div className={"player-detail__statistics-item__number"}> |
|
90
|
|
|
{player.field_stats_cards_red || "0"} |
|
91
|
|
|
</div> |
|
92
|
|
|
<div className={"player-detail__statistics-item__label"}> |
|
93
|
|
|
Rode kaarten |
|
94
|
|
|
</div> |
|
95
|
|
|
</section> |
|
96
|
|
|
</aside> |
|
97
|
|
|
) |
|
98
|
|
|
renderPlayerBirthdate = player => ( |
|
99
|
|
|
<div |
|
100
|
|
|
className={"player-detail__data-item player-detail__data-item--birthdate"} |
|
101
|
|
|
> |
|
102
|
|
|
<span className={"player-detail__data-item__label"}>Geboortedatum</span> |
|
103
|
|
|
<span className={"player-detail__data-item__data"}> |
|
104
|
|
|
{player.field_birth_date || "Onbekend"} |
|
105
|
|
|
</span> |
|
106
|
|
|
</div> |
|
107
|
|
|
) |
|
108
|
|
|
renderPlayerPosition = player => ( |
|
109
|
|
|
<div |
|
110
|
|
|
className={"player-detail__data-item player-detail__data-item--position"} |
|
111
|
|
|
> |
|
112
|
|
|
<span className={"player-detail__date-item__data"}> |
|
113
|
|
|
{player.field_position && mapPositionCode(player.field_position)} |
|
114
|
|
|
</span> |
|
115
|
|
|
<span className={"player-detail__data-item__label"}> |
|
116
|
|
|
{player.relationships.node__team && ( |
|
117
|
|
|
<Link to={player.relationships.node__team[0].path.alias}> |
|
118
|
|
|
{player.relationships.node__team[0].title} |
|
119
|
|
|
</Link> |
|
120
|
|
|
)} |
|
121
|
|
|
</span> |
|
122
|
|
|
</div> |
|
123
|
|
|
) |
|
124
|
|
|
renderPlayerJoinDate = player => { |
|
125
|
|
|
const currentlyPlaying = !player.field_date_leave |
|
126
|
|
|
return ( |
|
127
|
|
|
<div |
|
128
|
|
|
className={ |
|
129
|
|
|
"player-detail__data-item player-detail__data-item--joindate" |
|
130
|
|
|
} |
|
131
|
|
|
> |
|
132
|
|
|
<span className={"player-detail__data-item__label"}> |
|
133
|
|
|
{currentlyPlaying && "Speler bij KCVV sinds"} |
|
134
|
|
|
{!currentlyPlaying && "Speler tussen"} |
|
135
|
|
|
</span> |
|
136
|
|
|
<span className={"player-detail__data-item__data"}> |
|
137
|
|
|
{player.field_join_date || "Onbekend"} |
|
138
|
|
|
{!currentlyPlaying && ( |
|
139
|
|
|
<> |
|
140
|
|
|
<span className={"text--regular"}> en </span>{" "} |
|
141
|
|
|
{player.field_date_leave} |
|
142
|
|
|
</> |
|
143
|
|
|
)} |
|
144
|
|
|
</span> |
|
145
|
|
|
</div> |
|
146
|
|
|
) |
|
147
|
|
|
} |
|
148
|
|
|
renderPlayerData = player => ( |
|
149
|
|
|
<section className={"player-detail__data"}> |
|
150
|
|
|
{this.renderPlayerBirthdate(player)} |
|
151
|
|
|
{this.renderPlayerPosition(player)} |
|
152
|
|
|
{this.renderPlayerJoinDate(player)} |
|
153
|
|
|
</section> |
|
154
|
|
|
) |
|
155
|
|
|
renderPlayerBody = player => { |
|
156
|
|
|
const cleanBody = |
|
157
|
|
|
(player.body && |
|
158
|
|
|
player.body.processed.replaceAll( |
|
159
|
|
|
"/sites/default/", |
|
160
|
|
|
`${process.env.GATSBY_API_DOMAIN}/sites/default/` |
|
161
|
|
|
)) || |
|
162
|
|
|
"" |
|
163
|
|
|
|
|
164
|
|
|
return ( |
|
165
|
|
|
<section className={"player-detail__body"}> |
|
166
|
|
|
<div dangerouslySetInnerHTML={{ __html: cleanBody }} /> |
|
167
|
|
|
</section> |
|
168
|
|
|
) |
|
169
|
|
|
} |
|
170
|
|
|
render() { |
|
171
|
|
|
const { player } = this.props |
|
172
|
|
|
|
|
173
|
|
|
return ( |
|
174
|
|
|
<article className={"player-detail"}> |
|
175
|
|
|
{this.renderPlayerHeader(player)} |
|
176
|
|
|
{this.renderPlayerStats(player)} |
|
177
|
|
|
|
|
178
|
|
|
<div className={"player-break"}></div> |
|
179
|
|
|
|
|
180
|
|
|
{this.renderPlayerData(player)} |
|
181
|
|
|
|
|
182
|
|
|
{this.renderPlayerBody(player)} |
|
183
|
|
|
</article> |
|
184
|
|
|
) |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
export default PlayerDetail |
|
189
|
|
|
|